package com.gaogzhen.threadPool.scheduledThreadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j(topic = "c.TestScheduledThreadPool01")
public class TestScheduledThreadPool01 {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);
        log.debug("start...");
        pool.schedule(() -> {
            log.debug("task 1...");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("task 1 continue...");
            int i = 1 / 0;
            log.debug("task 1 end...");
        }, 1, TimeUnit.SECONDS);

        pool.schedule(() -> {
            log.debug("task 2...");
        }, 1, TimeUnit.SECONDS);
    }
}
